#include <string>
#include <stack>
using namespace std;
/*
 * @lc app=leetcode.cn id=20 lang=cpp
 *
 * [20] 有效的括号
 */

// @lc code=start
class Solution {
public:
    bool match(char a, char b) {
        return (a == '(' && b == ')') || (a == '[' && b == ']')
            || (a == '{' && b == '}');
    }


    bool isValid(string s) {
        stack<char> matcher;
        for (int i = 0; i < s.size(); i++) {
            if (!matcher.empty() && match(matcher.top(), s[i])) {
                matcher.pop();
            }
            else matcher.push(s[i]);
        }
        return matcher.empty();

    }
};
// @lc code=end

